/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ceair.flight.refund.util;

import java.util.Calendar;

/**
 * 包含D(天),N(分钟),H(小时),M(月)
 *
 * @author youguilin
 */
public enum RefundTimeUnits {

    MIN("N", Calendar.MINUTE),
    HOUR("H", Calendar.HOUR_OF_DAY),
    DAY("D", Calendar.DAY_OF_MONTH),
    MONTH("M", Calendar.MONTH);

    private final String code;
    private final int unit;

    RefundTimeUnits(String code, int unit) {
        this.code = code;
        this.unit = unit;
    }

    public String getCode() {
        return code;
    }

    public int getUnit() {
        return unit;
    }

    /**
     * 通过枚举<code>code</code>获得枚举。
     *
     * @param code 简码
     * @return 枚举
     */
    public static RefundTimeUnits getByCode(String code) {
        for (RefundTimeUnits status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        return null;
    }
}
